package cn.sofwin.core.service.impl;

import cn.sofwin.core.dao.BaseDao;
import cn.sofwin.core.entity.IdEntity;
import cn.sofwin.core.service.BaseService;

import java.util.List;

/**
 * 基础服务的实现
 * @author LetCode
 * @since 1.0
 */
public abstract class BaseServiceImpl<T extends IdEntity> implements BaseService<T> {

    protected abstract BaseDao<T> getDao();

    @Override
    public T create(T entity) {
        int id = getDao().insert(entity);
        entity.setId(id);
        return entity;
    }

    @Override
    public T save(T entity) {
        getDao().update(entity);
        return entity;
    }

    @Override
    public void remove(Integer id) {
        getDao().deleteById(id);
    }

    @Override
    public T get(Integer id) {
        return getDao().get(id);
    }

    @Override
    public List<T> all() {
        return getDao().all();
    }
}
